<?php

namespace App\Http\Controllers\backend;

use Illuminate\Support\Facades\DB;
use App\Http\Controllers\Controller;
use App\Model\Backend\MessageModel;

class  MessageController extends  Controller{

    //未读消息的数量
    public  function  count(){
        $uid= session('member')['uid'];
        $count = DB::table('message')->where('uid',$uid)->where('status',0)->count();

        $data =['count'=>$count];
        echo json_encode($data);
    }

    //消息的详情
    public  function index(){
        $uid= session('member')['uid'];
        $message = DB::table('message')->where('uid',$uid)->orderBy('id', 'desc')->paginate(10);
        //消息的状态改变，从未读到已读
       DB::table('message')->where('id','>',0)->where('uid',$uid)->update(['status'=>"1"]);

        return view('backend.message.index',['message'=>$message]);

    }
    
}